$(function(){
    $('ul.sortable').nestedSortable({
        disableNesting: 'no-nest',
        forcePlaceholderSize: true,
        handle: 'span',
        helper: 'clone',
        items: 'li',
        maxLevels: 2,
        listType: 'ul', 
        opacity: .6,
        placeholder: 'placeholder',
        revert: 250,
        tabSize: 25,
        tolerance: 'pointer',
        toleranceElement: '> span',
        update: function () {
            var list = $(this).nestedSortable('toArray');
            var json = JSON.stringify(list);
            $.ajax({
                type: 'POST',
                url: '/news/update_category_order/',
                data: { list: json },
                dataType: 'json',
                success: function(data) {
                    console.log(json);
                }
            });
        }
    });
    $('#serialize').on('click',function(e){
        e.preventDefault();
        var lista = $('ul.sortable').nestedSortable('serialize');
        //var lista = $('ul.sortable').nestedSortable('toArray', {startDepthCount: 0});
        console.log(lista);
    });
}); 